// pages/detail/detail.js
Page({
  data: {
    itemId: null,
    itemData:{},
    showModal:false
  },

  onLoad(pageOptions) {
    //const app = getApp();
    //const globalParams = app.globalData.urlParams;
    
    // 优先级：页面参数 > 全局参数
    const itemId = pageOptions.id || ''
    
    if (!itemId) {
      //my.alert({ title: '错误', content: '缺少参数id' });
      return;
    }

    this.setData({ itemId });
    this.fetchData(itemId); // 调用接口
  },
  showModal() { this.setData({ showModal: true }) },
  hideModal() { this.setData({ showModal: false }) },
  confirm() { 
    // 处理确认逻辑
    this.hideModal();
  },
  // 调用API示例（带参数）
  fetchData(id) {
    my.request({
      url: 'https://api.example.com/data',
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      data: { 
        id, 
        //timestamp: Date.now() 
      },
      success: (res) => {
        if (res.data.code === 200) {
          this.setData({ itemData: res.data.result });
        }
      },
      fail: (err) => {
        my.showToast({ content: `请求失败: ${err.errorMessage}` });
      }
    });
  }
});